package cn.jly.spring.annotation.ioc.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author lanyangji
 * @description person bean
 * @date 2020/11/12 上午 8:34
 */
public class Person implements ApplicationContextAware {
    /**
     * 正常bean使用 applicationContext
     */
    private ApplicationContext applicationContext;

    /**
     * @value
     * 1. 基本数值
     * 2. spEL
     * 3. ${}，取出配置文件中的值
     */
    @Value("张三")
    private String name;
    @Value("#{20 - 2}")
    private Integer age;

    public void init() {
        System.out.println("Person.init 初始化方法");
    }

    private void destroy() {
        System.out.println("Person.destroy 销毁方法");
    }

    public Person() {
    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
